﻿// Copyright (c) 2012 - 2021 Jared Zheng <jaredz at outlook dot com>
// Buddha Framework is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//          http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.
//
// Create : 2012-12-01 version 0.1 Jared Zheng <jaredz at outlook dot com>
// Update : 2021-03-19 version 4.0.0 Jared Zheng <jaredz at outlook dot com>

#ifndef __PACKET_DEFINE_INL__
#define __PACKET_DEFINE_INL__

#pragma once

///////////////////////////////////////////////////////////////////////////////////////////////////////////
// CPAKHeadBase : 信令包数据头
INLINE CPAKHeadBase::CPAKHeadBase(UEVENT uEvent, URANK uRank, USID uSid, UDATA uData)
: m_uEvent(uEvent)
, m_uRank(uRank)
, m_uSid(uSid)
, m_uData(uData)
{
}

INLINE CPAKHeadBase::~CPAKHeadBase(void)
{
}

INLINE CPAKHeadBase::CPAKHeadBase(const CPAKHeadBase& aSrc)
: m_uEvent(aSrc.m_uEvent)
, m_uRank(aSrc.m_uRank)
, m_uSid(aSrc.m_uSid)
, m_uData(aSrc.m_uData)
{
}

INLINE CPAKHeadBase& CPAKHeadBase::operator=(const CPAKHeadBase& aSrc)
{
    if (&aSrc != this)
    {
        m_uEvent = aSrc.m_uEvent;
        m_uRank  = aSrc.m_uRank;
        m_uSid   = aSrc.m_uSid;
        m_uData  = aSrc.m_uData;
    }
    return (*this);
}

INLINE size_t CPAKHeadBase::Length(void) const
{
    return (sizeof(UEVENT) + sizeof(URANK) + sizeof(USID) + sizeof(UDATA));
}

INLINE void CPAKHeadBase::Serialize(CStream& Stream)
{
    if (Stream.IsRead())
    {
        Stream >> m_uEvent >> m_uRank >> m_uSid >> m_uData;
    }
    else
    {
        Stream << m_uEvent << m_uRank << m_uSid << m_uData;
    }
}

INLINE bool CPAKHeadBase::IsStream(void) const
{
    return false;
}

INLINE bool CPAKHeadBase::Bind(CNetworkPtr&, CNetParam*)
{
    return false;
}

INLINE UEVENT CPAKHeadBase::GetEvent(void) const
{
    return m_uEvent;
}

INLINE void CPAKHeadBase::SetEvent(UEVENT uEvent)
{
    m_uEvent = uEvent;
}

INLINE URANK CPAKHeadBase::GetRank(void) const
{
    return m_uRank;
}

INLINE void CPAKHeadBase::SetRank(URANK uRank)
{
    m_uRank = uRank;
}

INLINE USID CPAKHeadBase::GetSid(void) const
{
    return m_uSid;
}

INLINE void CPAKHeadBase::SetSid(USID uSid)
{
    m_uSid = uSid;
}

INLINE UDATA CPAKHeadBase::GetData(void) const
{
    return m_uData;
}

INLINE void CPAKHeadBase::SetData(UDATA uData)
{
    m_uData = uData;
}

INLINE void CPAKHeadBase::Reset(UEVENT uEvent, URANK uRank, USID uSid, UDATA uData)
{
    SetEvent(uEvent);
    SetRank(uRank);
    SetSid(uSid);
    SetData(uData);
}

#endif // __PACKET_DEFINE_INL__
